Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using get function of dictionary #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Using get function of dictionary #18

wants to merge 1 commit into from

Conversation

lokendra1704
Copy link

No description provided.

@YuriSpiridonov
Copy link
Owner

I tried to submit new code with .get() function on LeetCode and faced a Runtime Error

AttributeError: 'NoneType' object has no attribute 'append'
    queue[depth+1] = queue.get(depth+1,[]).append(node.right)
Line 23 in levelOrder (Solution.py)
    ret = Solution().levelOrder(param_1)
Line 43 in _driver (Solution.py)
    _driver()
Line 54 in <module> (Solution.py)

but after I replaced

if node.left:
    queue[depth+1] = queue.get(depth+1,[]).append(node.left)

with

if node.left:
    queue[depth+1] = queue.get(depth+1,[])
    queue[depth+1].append(node.left)

It works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants